home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / button12.lha / circtext.ps < prev    next >
Text File  |  1993-08-05  |  6KB  |  137 lines

  1. %
  2. % circtext.ps - render text strings around arcs
  3. %
  4. % From Adobe Cookbook
  5. % Program: Circular Text     Number: 16
  6. %-----------------------------------------------------------------------------
  7. %
  8. /outsidecircletext                          % outsidecircletext places text
  9.   { $circtextdict begin                     % around a circular arc. The
  10.       /radius exch def                      % baseline of the text is placed
  11.       /centerangle exch def                 % on the outside of the
  12.       /ptsize exch def                      % circumference of the circle in a
  13.       /str exch def                         % clockwise fashion.
  14.                         % outsidecircletext takes four
  15.                         % arguments: the string to be
  16.                         % printed, the point size of the
  17.                         % font being used, the angle
  18.                         % around which the text should be
  19.                         % centered and the radius of the
  20.                         % circular arc. It assumes that
  21.                         % the center of the circle is at
  22.                         % (0,0).
  23.       /xradius radius ptsize 4 div add      % A radius that is slightly larger
  24.     def                                 % than the one specified is used
  25.                         % for computations but not for
  26.                         % placement of characters. Using a
  27.                         % slightly larger radius in the
  28.                         % computations places the
  29.                         % characters closer together,
  30.                         % otherwise the interletter
  31.                         % spacing is too loose.
  32.       gsave                                 % Save the current graphics state.
  33.     centerangle str findhalfangle       % Find out how much angle the
  34.       add rotate                        % string subtends and then rotate
  35.                         % to the appropriate starting
  36.                         % position for showing the string.
  37.                         % (The positive x-axis now
  38.                         % intersects the circle where the
  39.                         % text should start.)
  40.     str
  41.       { /charcode exch def              % For each character in the
  42.         ( ) dup 0 charcode put          % string, determine its position
  43.           outsideshowcharandrotate      % on the circular arc and show it.
  44.       } forall
  45.       grestore                              % Return to the former graphics
  46.                         % state.
  47.     end
  48.   } def
  49.        
  50. /insidecircletext                           % insidecircletext works very
  51.   { $circtextdict begin                     % similarly to outsidecircletext
  52.       /radius exch def                      % except that the baseline of the
  53.       /centerangle exch def                 % text is placed on the inside of
  54.       /ptsize exch def                      % the circumference of the circle
  55.       /str exch def                         % in a counter-clockwise fashion.
  56.                         % insidecircletext takes the same
  57.                         % four arguments as
  58.                         % outsidecircletext.
  59.                                 
  60.       /xradius radius ptsize 3 div sub      % Here we use a radius which is
  61.     def                                 % slightly smaller than the
  62.                         % desired radius for computations.
  63.                         % This forces the characters to be
  64.                         % placed farther apart to avoid
  65.                         % overlapping.
  66.       gsave
  67.     centerangle str findhalfangle
  68.       sub rotate
  69.     str
  70.       { /charcode exch def
  71.         ( ) dup 0 charcode put
  72.           insideshowcharandrotate
  73.       } forall
  74.       grestore
  75.     end
  76.   } def
  77. /$circtextdict 16 dict def
  78. $circtextdict begin
  79.   /findhalfangle                            % findhalfangle takes one
  80.     { stringwidth pop 2 div                 % argument, a string, and finds
  81.     2 xradius mul pi mul div 360 mul    % the angle subtended by that
  82.     } def                                   % string. It leaves the value of
  83.                         % half of that angle on the stack.
  84.                         % The angle is found by computing
  85.                         % the ratio of the width of the
  86.                         % string to the circumference of
  87.                         % the circle and then converting
  88.                         % that value to degrees.
  89.                                     
  90.   /outsideshowcharandrotate                 % This procedure shows a character
  91.     { /char exch def                        % upright on the outside of the
  92.       /halfangle char findhalfangle def     % circumference and then rotates
  93.       gsave                                 % clockwise by the amount of angle
  94.                         % subtended by the width of the
  95.                         % character.
  96.     halfangle neg rotate                % Rotate clockwise by half the
  97.     radius 0 translate                  % angle taken up by the width of
  98.                         % the character and translate out
  99.                         % to the circumference.
  100.     -90 rotate                          % Position character upright on
  101.                         % outside of circumference.
  102.     char stringwidth pop 2 div neg      % Center the character around the
  103.                         % origin.
  104.       0 moveto char show
  105.       grestore
  106.       halfangle 2 mul neg rotate            % Rotate clockwise by the amount
  107.     } def                                   % of angle subtended by the width
  108.                         % of the character.
  109.                                    
  110.   /insideshowcharandrotate                  % insideshowcharandrotate operates
  111.     { /char exch def                        % in a similar manner to
  112.       /halfangle char findhalfangle def     % outsideshowcharandrotate except
  113.       gsave                                 % that the direction of rotation
  114.     halfangle rotate                    % is counter-clockwise and the
  115.     radius 0 translate                  % characters are placed upright on
  116.     90 rotate                           % the inside of the circle.
  117.     char stringwidth pop 2 div neg
  118.       0 moveto char show
  119.       grestore
  120.       halfangle 2 mul rotate
  121.     } def
  122.      
  123.   /pi 3.1415923 def
  124. end
  125.  
  126. % Don't need to print out this example for use as a library:
  127. %/Times-Bold findfont 15 scalefont setfont
  128. %306 448 translate
  129. %(Symphony No. 9 (from the New World))
  130. %  15 90 100 outsidecircletext
  131. %/Times-Roman findfont 10 scalefont setfont
  132. %(Antonin Dvorak)
  133. %  10 90 84 outsidecircletext
  134. %(The New York Philharmonic Orchestra)
  135. %  10 270 84 insidecircletext
  136. %showpage
  137.